<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="emp.name">
  <input type="text" placeholder="请输入员工工资" v-model="emp.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="emp.job">
  <button @click="addEmp()">点我添加</button>
  <hr>
  <table border="1px">
    <tr>
      <th>编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(arr,index) in empArr">
      <td>{{index+1}}</td>
      <td>{{arr.name}}</td>
      <td>{{arr.salary}}</td>
      <td>{{arr.job}}</td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

// const ename = ref('');
// const esal = ref('');
// const ejob = ref('');
const emp = ref({
  name:'',salary:'',job:''
});
const empArr = ref([]);

const addEmp = ()=>{
  if (emp.value.name.trim()==''||emp.value.salary.trim()==''||emp.value.job.trim()==''){
    alert('请输入员工信息！');
    return;
  }
  empArr.value.push(emp.value);
  emp.value = {
    name:'',salary:'',job:''
  };
}
</script>


<style scoped>

</style>